unit Con_Usua;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,dm,
  db,dbtables,clsUsuario;

type
  TfrmCon_usua = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    btnBusca: TBitBtn;
    dbgUsuario: TDBGrid;
    procedure FormActivate(Sender: TObject);
    procedure btnBuscaClick(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure dbgUsuarioCellClick(Column: TColumn);
    procedure BtnFecharClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    cod_usua:string;
  end;

var frmCon_usua:TfrmCon_usua;

implementation

{$R *.DFM}

var usuario    : Tusuario;
    tds        : Tdatasource;
    tq         : Tquery;


procedure TfrmCon_usua.FormActivate(Sender: TObject);
begin
  inherited;
  tds:=TDataSource.create(FrmCon_usua);
  tds.name:='dsUsuario';
  tq:=Tquery.create(FrmCon_usua);
  tq.databasename:=dm.dmint.db.databasename;
  tq.name:='qUsuario';
  tq.active:=False;
  tds.DataSet:=tq;
  dbgUsuario.DataSource:=tds;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TfrmCon_usua.btnBuscaClick(Sender: TObject);
begin
  inherited;
  FazConsulta;
  edtNome.setfocus;
end;

procedure TfrmCon_usua.edtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key=12 then begin
    FazConsulta;
    edtNome.setfocus;
  end;
end;

procedure TfrmCon_usua.dbgUsuarioCellClick(Column: TColumn);
begin
  inherited;
  edtnome.text := tq.fieldbyname('nome').asstring;
  edtnome.setfocus;
end;

procedure TfrmCon_usua.FazConsulta;
begin
  usuario:=Tusuario.Create;
  if edtnome.text='' then
   usuario.Consultar(tq,' ')
  else
   usuario.Consultar(tq,edtnome.text);
  tq.open;
  usuario.free;
end;

procedure TfrmCon_usua.BtnFecharClick(Sender: TObject);
begin
  inherited;
  cod_usua:=tq.fieldbyname('cod_usua').asstring;
  tds.free;
  tq.free;
end;

end.
